package com.example.myapplication.view;

import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.navigation.fragment.NavHostFragment;

import com.example.myapplication.R;
import com.example.myapplication.databinding.FragmentFirstBinding;
import com.example.myapplication.widgets.calendar.work.TimeWork;

import java.util.ArrayList;
import java.util.List;

@FragmentName("周试图一")
public class WeekOneFragment extends Fragment {

    private FragmentFirstBinding binding;

    @Override
    public View onCreateView(
            @NonNull LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState
    ) {
        binding = FragmentFirstBinding.inflate(inflater, container, false);
        return binding.getRoot();
    }

    public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        binding.buttonFirst.setOnClickListener(view1 ->
                NavHostFragment.findNavController(WeekOneFragment.this)
                        .navigate(R.id.action_FirstFragment_to_SecondFragment));
        binding.buttonSecond.setOnClickListener(v ->
                NavHostFragment.findNavController(WeekOneFragment.this)
                        .navigate(R.id.action_FirstFragment_to_MonthOneFragment));

        binding.add.setOnClickListener(v -> {
            TimeWork timeWork;
            timeWork = new TimeWork();
            timeWork.setId("新增");
            timeWork.setTitle("新增");
            timeWork.setTime("09:05:52");
            timeWork.setDate("2023-05-22");
            timeWork.setBgColor(Color.YELLOW);
            binding.timeTable.addWork(timeWork);
        });
        binding.delete.setOnClickListener(v -> {
            binding.timeTable.removeWork("新增");
        });

        binding.timeTable.setOnClickWorkItemListener((date, time, nextTime, workList, timeWork) ->
                Toast.makeText(getContext(), date + " " + time + (timeWork == null ? "" : " " + timeWork.getTitle()) +
                        (workList != null && !workList.isEmpty() ? " 共" + workList.size() + "条" : ""), Toast.LENGTH_SHORT).show());

        binding.timeTable.setDate(2023, 5, 26);
        binding.timeTable.setShowTip(true);
        binding.timeTable.setOnlyShowTitle(false);

        List<TimeWork> workList = new ArrayList<>();
        TimeWork timeWork;
        timeWork = new TimeWork();
        timeWork.setTitle("哈哈哈哈哈哈哈哈哈哈哈哈");
        timeWork.setTime("全天");
        timeWork.setDate("2023-05-24");
        timeWork.setBgColor(Color.RED);
        workList.add(timeWork);
        timeWork = new TimeWork();
        timeWork.setTitle("哈哈哈哈哈哈123哈哈哈哈哈哈");
        timeWork.setTime("01:05:52");
        timeWork.setDate("2023-05-24");
        timeWork.setBgColor(Color.RED);
        workList.add(timeWork);
        timeWork = new TimeWork();
        timeWork.setTitle("哈哈哈哈哈哈");
        timeWork.setTime("00:05:52");
        timeWork.setDate("2023-05-22");
        timeWork.setBgColor(Color.RED);
        workList.add(timeWork);
        timeWork = new TimeWork();
        timeWork.setTitle("哈哈哈哈哈哈");
        timeWork.setTime("01:05:52");
        timeWork.setDate("2023-05-23");
        timeWork.setBgColor(Color.RED);
        workList.add(timeWork);
        timeWork = new TimeWork();
        timeWork.setTitle("哈哈哈哈哈哈");
        timeWork.setTime("09:05:52");
        timeWork.setDate("2023-05-22");
        timeWork.setBgColor(Color.RED);
        workList.add(timeWork);
        timeWork = new TimeWork();
        timeWork.setTitle("哈哈哈哈哈哈");
        timeWork.setTime("11:05:52");
        timeWork.setDate("2023-05-23");
        timeWork.setBgColor(Color.RED);
        workList.add(timeWork);
        timeWork = new TimeWork();
        timeWork.setTitle("51hhhbbbbbbnnnnn");
        timeWork.setTime("01:05:52");
        timeWork.setDate("2023-05-24");
        timeWork.setBgColor(Color.BLACK);
        workList.add(timeWork);
        timeWork = new TimeWork();
        timeWork.setTitle("fffad");
        timeWork.setTime("01:05:52");
        timeWork.setDate("2023-05-24");
        timeWork.setBgColor(Color.BLUE);
        workList.add(timeWork);
        timeWork = new TimeWork();
        timeWork.setTitle("健康的减肥");
        timeWork.setTime("01:05:52");
        timeWork.setDate("2023-05-24");
        timeWork.setBgColor(Color.RED);
        workList.add(timeWork);
        timeWork = new TimeWork();
        timeWork.setTitle("的费尔法v");
        timeWork.setTime("01:05:52");
        timeWork.setDate("2023-05-24");
        timeWork.setBgColor(Color.BLUE);
        workList.add(timeWork);
        timeWork = new TimeWork();
        timeWork.setTitle("阿塞飞");
        timeWork.setTime("03:05:52");
        timeWork.setDate("2023-05-25");
        timeWork.setBgColor(Color.GREEN);
        workList.add(timeWork);
        timeWork = new TimeWork();
        timeWork.setTitle("二分");
        timeWork.setTime("06:05:52");
        timeWork.setDate("2023-05-26");
        timeWork.setBgColor(Color.RED);
        workList.add(timeWork);
        timeWork = new TimeWork();
        timeWork.setTitle("发到饭否");
        timeWork.setTime("08:05:52");
        timeWork.setDate("2023-05-28");
        timeWork.setBgColor(Color.RED);
        workList.add(timeWork);
        timeWork = new TimeWork();
        timeWork.setTitle("发2发21发");
        timeWork.setTime("09:05:52");
        timeWork.setDate("2023-05-26");
        timeWork.setBgColor(Color.RED);
        workList.add(timeWork);
        timeWork = new TimeWork();
        timeWork.setTitle("发射东风2 1");
        timeWork.setTime("12:05:52");
        timeWork.setDate("2023-05-26");
        timeWork.setBgColor(Color.RED);
        workList.add(timeWork);
        timeWork = new TimeWork();
        timeWork.setTitle("发士大夫21");
        timeWork.setTime("12:05:52");
        timeWork.setDate("2023-05-26");
        timeWork.setBgColor(Color.RED);
        workList.add(timeWork);
        timeWork = new TimeWork();
        timeWork.setTitle("发士大夫21");
        timeWork.setTime("23:05:52");
        timeWork.setDate("2023-05-26");
        timeWork.setBgColor(Color.RED);
        workList.add(timeWork);
        timeWork = new TimeWork();
        timeWork.setTitle("发士大夫21");
        timeWork.setTime("23:05:52");
        timeWork.setDate("2023-05-26");
        timeWork.setBgColor(Color.RED);
        workList.add(timeWork);
        timeWork = new TimeWork();
        timeWork.setTitle("发士大夫21");
        timeWork.setTime("23:05:52");
        timeWork.setDate("2023-05-26");
        timeWork.setBgColor(Color.RED);
        workList.add(timeWork);
        timeWork = new TimeWork();
        timeWork.setTitle("发士大夫21");
        timeWork.setTime("23:05:52");
        timeWork.setDate("2023-05-26");
        timeWork.setBgColor(Color.RED);
        workList.add(timeWork);
        timeWork = new TimeWork();
        timeWork.setTitle("发士大夫21");
        timeWork.setTime("23:05:52");
        timeWork.setDate("2023-05-26");
        timeWork.setBgColor(Color.RED);
        workList.add(timeWork);
        timeWork = new TimeWork();
        timeWork.setTitle("发士大夫21");
        timeWork.setTime("23:05:52");
        timeWork.setDate("2023-05-26");
        timeWork.setBgColor(Color.RED);
        workList.add(timeWork);
        timeWork = new TimeWork();
        timeWork.setTitle("发士大夫21");
        timeWork.setTime("23:05:52");
        timeWork.setDate("2023-05-26");
        timeWork.setBgColor(Color.RED);
        workList.add(timeWork);
        timeWork = new TimeWork();
        timeWork.setTitle("发士大夫21");
        timeWork.setTime("23:05:52");
        timeWork.setDate("2023-05-26");
        timeWork.setBgColor(Color.RED);
        workList.add(timeWork);
        timeWork = new TimeWork();
        timeWork.setTitle("发士大夫21");
        timeWork.setTime("23:05:52");
        timeWork.setDate("2023-05-26");
        timeWork.setBgColor(Color.RED);
        workList.add(timeWork);
        timeWork = new TimeWork();
        timeWork.setTitle("发士大夫21");
        timeWork.setTime("23:05:52");
        timeWork.setDate("2023-05-30");
        timeWork.setBgColor(Color.RED);
        workList.add(timeWork);
        binding.timeTable.setWorkList(workList);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        binding = null;
    }

}